//
//  ChatBubble.m
//  UIImage程序
//
//  Created by mir_yan on 2018/10/2.
//  Copyright © 2018年 hakeem. All rights reserved.
//

#import "ChatBubble.h"

// 全局
#define kFontSize 20
#define kMaxWidth [UIScreen mainScreen].bounds.size.width - 100


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@interface ChatBubble()

@property (strong, nonatomic) UILabel* textLabel;

@end

@implementation ChatBubble

// 初始化方法
//- (instancetype)init
//{
//    self = [super init];
//    if (self) {
//        <#statements#>
//    }
//    return self;
//}

// 使用可实话编辑时候， 加载可视化界面控件，会调动如下方法
//- (instancetype)initWithCoder:(NSCoder *)aDecoder {
//    self = [super init];
//    if (self) {
//        <#statements#>
//    }
//    return self;
//}
// 代码创建
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // 设置img
        UIImage * image = [UIImage imageNamed:@"swiper"];
        image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(50, 30, 15, 15) resizingMode:UIImageResizingModeStretch];
        self.image = image;
        
        [self addSubview:self.textLabel];
    }
    return self;
}

- (UILabel*)textLabel {
    if (_textLabel == nil) {
        _textLabel = [[UILabel alloc] init];
        _textLabel.font = [UIFont systemFontOfSize:kFontSize];
        _textLabel.numberOfLines = 0;
        _textLabel.backgroundColor = [UIColor redColor];
    }
    return _textLabel;
}

- (void)setText:(NSString*)text {
    
    self.textLabel.text = text;
    
    
    // 根据文字确定大小
//    CGSize textSize = [text boundingRectWithSize:CGSizeMake(kMaxWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:kFontSize]} context:nil];
    
//    self.textLabel.frame = CGRectMake(30, 12, textSize.width, textSize.height);
    
}

@end
